﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace BinaryTree
{
    public class DrawTree:Panel
    {
        private Graphics _graphics;
        private int dy = 50;
        Brush b = new HatchBrush(HatchStyle.Percent05, Color.Black);
        Brush c = new HatchBrush(HatchStyle.Percent90, Color.Red);
        Pen pen = new Pen(Color.FromArgb(255, 8, 6, 9), 1);
        public void Draw(treeNode _root)
        {
            Width = 1024;
            Height = 768;
            BackgroundImage = new Bitmap(Width, Height);
            _graphics = Graphics.FromImage(BackgroundImage);
            IVisitDraw v = new VDraw();
            VDraw._graphics = _graphics;
            TraverseVLR(_root, v, Width / 2, 0, Width / 2, Width / 2);
        }
        public void TraverseVLR(treeNode _root, IVisitDraw v, int x, int y, int xp, int dx)
        {
            if (_root != null)
            {
                v.Visit(_root,x, y, xp, dx);
                TraverseVLR(_root.left, v, xp, y + dy, xp - dx / 2, dx / 2);
                TraverseVLR(_root.right, v,xp, y + dy, xp + dx / 2, dx / 2);
            }
        }
    }
}
